import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Alert } from '../entities/alert.entity';

@Injectable()
export class AlertsService {
  constructor(
    @InjectRepository(Alert)
    private alertRepository: Repository<Alert>,
  ) {}

  async findAll(): Promise<Alert[]> {
    return this.alertRepository.find({ relations: ['server', 'project'] });
  }

  async create(alertData: Partial<Alert>): Promise<Alert> {
    const alert = this.alertRepository.create(alertData);
    return this.alertRepository.save(alert);
  }
}